/*********************************************************
*Copyright (c) 2009 Rob Groves. All Rights in Pw 
*@des: 管理Client/Session 
*@name: clientmgr.cpp
*@author: zhongsx
*@time: 2015-03-03
*********************************************************/

#include "ClientMgr.h"

boost::shared_ptr<ClientMgr> ClientMgr::pMgr;

boost::shared_ptr<ClientMgr>& ClientMgr::GetClietMgr()
{
	if (!pMgr){
		pMgr = boost::shared_ptr<ClientMgr>(new ClientMgr());
	}
	return pMgr;
}

ClientMgr::ClientMgr()
{

}

ClientMgr::~ClientMgr()
{

}

void ClientMgr::push(boost::shared_ptr<client>& pClient)
{
	boost::mutex::scoped_lock lock(mutex_); 
	std::list<boost::shared_ptr<client> >::iterator it;
	it = std::find(client_list.begin(), client_list.end(), pClient);
	if (it == client_list.end()){
		client_list.push_back(pClient);
	}
}

void ClientMgr::pop(boost::shared_ptr<client>& pClient)
{
	boost::mutex::scoped_lock lock(mutex_); 
	client_list.remove(pClient);
}

std::list<boost::shared_ptr<client> > ClientMgr::getlist()
{
	return client_list;
}